<template>
    <div class="reportmian">
        <el-collapse v-model="activeNames">
            <el-collapse-item title="数据筛选" name="1">
                <el-form :inline="true" class="divstyle" :model="selectfrom">
                    <el-form-item label="项目">
                        <el-select  filterable placeholder="请选择项目" v-model="selectfrom.Project">
                            <el-option :value="0" label="全部"></el-option>
                            <el-option v-for="v in AllProject" :label="v.ProjectName" :value="v.Id"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="项目类型">
                        <el-select filterable  placeholder="请选择项目类型" v-model="selectfrom.ProjectType">
                            <el-option :value="0" label="全部"></el-option>
                            <el-option :value="1" label="施工生产"></el-option>
                            <el-option :value="2" label="产品生产"></el-option>
                            <el-option :value="4" label="产品研发"></el-option>
                            <el-option :value="8" label="技术服务"></el-option>
                            <el-option :value="16" label="其他"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item>
                        <el-date-picker
                                v-model="selectfrom.Start"
                                type="date"
                                placeholder="开始时间"
                                value-format="yyyy-MM-dd"
                                format="yyyy - MM - dd">
                        </el-date-picker>
                    </el-form-item>
                    <el-form-item>
                        <el-date-picker
                                v-model="selectfrom.End"
                                type="date"
                                placeholder="结束时间"
                                value-format="yyyy-MM-dd"
                                format="yyyy - MM - dd">
                        </el-date-picker>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="success" icon="el-icon-search" @click="formdata"></el-button>
                    </el-form-item>
                </el-form>
            </el-collapse-item>
            <el-collapse-item title="数据面板" name="2">
                <el-row>
                    <el-col align="center" style="font-size: 25px;font-weight: bold;">固远晨通科技发展有限公司项目人工费支出台账</el-col>
                    <el-col>
                        <el-table :data="tableData"  border>
                            <el-table-column fixed type="index" label="序号" width="50" align="center" :index="indexMethod"></el-table-column>
                            <el-table-column label="项目编号" align="center" width="180" prop="ProjectNumber"></el-table-column>
                            <el-table-column label="项目名称" align="center" width="240" show-overflow-tooltip prop="ProjectName"></el-table-column>
                            <el-table-column label="有无合同" align="center" show-overflow-tooltip >
                                <template slot-scope="slot">
                                    <label v-if="slot.row.ContractId==0"></label>
                                    <label v-else>有</label>
                                </template>
                            </el-table-column>
                            <el-table-column label="签订时间" align="center" show-overflow-tooltip >
                                <template slot-scope="slot">
                                    {{ fmtDateNew(slot.row.SignDate) }}
                                </template>
                            </el-table-column>
                            <el-table-column label="合同名称" align="center" show-overflow-tooltip prop="Title"></el-table-column>
                            <el-table-column label="客户" align="center" show-overflow-tooltip >
                                <template slot-scope="slot">
                                    {{ GetCustomerName(slot.row.CustomerId) }}
                                </template>
                            </el-table-column>
                            <el-table-column label="合同额" align="center" show-overflow-tooltip prop="ContractPrice"></el-table-column>
                            <el-table-column label="结算金额" align="center" show-overflow-tooltip prop="SettleMoney"></el-table-column>
                            <el-table-column label="应付劳务人工费" align="center" show-overflow-tooltip prop="CopeWithLabour"></el-table-column>
                            <el-table-column label="已付劳务人工费" align="center" show-overflow-tooltip prop="PaidLabour"></el-table-column>
                            <el-table-column label="未付劳务人工费" align="center" show-overflow-tooltip prop="UnpaidLabour"></el-table-column>
                            <el-table-column label="人工（公司费）" align="center" show-overflow-tooltip prop="LaborExpenses"></el-table-column>
                        </el-table>
                    </el-col>
                </el-row>
            </el-collapse-item>
            <div class="block">
                <el-pagination
                        @size-change="formdata"
                        @current-change="formdata"
                        :current-page.sync="pagination.currentPage"
                        :page-sizes="pagination.pagesizes"
                        :page-size.sync="pagination.pagesize"
                        layout="total, sizes, prev, pager, next, jumper"
                        :total.sync="pagination.total">
                </el-pagination>
            </div>
        </el-collapse>
    </div>
</template>

<script>
    export default {
        name: "ProjectLaborExpensesReport",
        props:{
            AllProject:{
                type:Array,
                required:true
            },
            AllCustomer:{
                type:Array,
                required:true
            }
        },
        data(){
            return{
                activeNames: ['1','2'],
                selectfrom:{
                    Start:'',
                    End:'',
                    ProjectType:0,
                    Project:0,
                },
                tableData:[],
                //分页数据绑定
                pagination:{
                    currentPage:1,
                    pagesizes:[10, 20, 30, 40,50],
                    pagesize:10,
                    total:100
                },
            }
        },
        created() {
            this.InitDate();
            this.formdata()
        },
        methods: {
            InitDate() {
                const endDate = this.getFormatDate(new Date()).substr(0, 11)
                const beginDate = this.getFormatDate(new Date(new Date() - 3600 * 1000 * 24 * 30)).substr(0, 11)
                this.selectfrom.Start = beginDate;
                this.selectfrom.End = endDate;
            },
            // 获取当前时间
            getFormatDate(date) {
                var month = date.getMonth() + 1
                var strDate = date.getDate()
                if (month >= 1 && month <= 9) {
                    month = '0' + month
                }
                if (strDate >= 0 && strDate <= 9) {
                    strDate = '0' + strDate
                }
             var currentDate = date.getFullYear() + '-' + month + '-' + strDate + '';
                return currentDate
            },
            //表格数据序列号
            indexMethod(index){
                return ((this.pagination.currentPage-1)*this.pagination.pagesize)+index+1
            },
            // 初始数据加载
            formdata() {
                let loadding = this.openLoading();
                this.$http.post('Report/GetProjectLaborExpensesReportData',{
                    from:this.selectfrom,
                    currentPage:this.pagination.currentPage,
                    pagesize:this.pagination.pagesize,
                }).then(res => {
                    loadding.close();
                    this.tableData = res.data.data
                    this.pagination.total=res.data.count
                })
            },
            //时间转化
            fmtDateNew(val){
                if (val !='' && val != null){
                    let newtime=val.split(' ')[0]
                    return newtime
                }else{
                    return ''
                }
            },
            //获取客户名称
            GetCustomerName(val){
                let name=''
                for (let i=0; i<this.AllCustomer.length; i++){
                    if (this.AllCustomer[i].Id == val){
                        name = this.AllCustomer[i].CustomerName
                        return name
                    }
                }
            },
            //小数点保留
            TaxPaytoFixed(val){
                let data=''
                if (val!=''){
                    data = val.toFixed(2)
                }
                return data
            },
            percentagetoFixed(val){
                let data = ''
                if (val != ''){
                    data = val.toFixed(2)
                    data +='%'
                }
                return data
            },
        },
    }
</script>

<style scoped>
    .block{
        float: right;
    }
</style>
